namespace CSharpPro2._1016;

public class Demo
{
    //键盘输入三个整数x、y、z，请把这三个数由小到大输出
    public void TestPrint()
    {
        int x = Convert.ToInt32(Console.ReadLine());
        int y = Convert.ToInt32(Console.ReadLine());
        int z = Convert.ToInt32(Console.ReadLine());
        if (x > y)
        {
            int temp = x;
            x = y;
            y = temp;
        }

        if (x > z)
        {
            int temp = x;
            x = z;
            z = temp;
        }

        if (y > z)
        {
            int temp = y;
            y = z;
            z = temp;
        }

        Console.WriteLine($"{x} {y} {z}");
    }

    //打印出1-100之间所有不是7的倍数和不包含7的数字， 并求和。
    public void TestPrint2()
    {
        int num = 0;
        int count = 0;
        for (int i = 1; i <= 100; i++)
        {
            int num1 = i / 10;
            int num2 = i % 10;
            if (i % 7 != 0 && num1 != 7 && num2 != 7)
            {
                num += i;
                Console.Write($"{i}  ");
            }
        }

        Console.WriteLine($"{num}  ");
    }

    //打印九九乘法表
    public void TestPrint3()
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write($"{j} * {i} = {j * i}  ");
            }

            Console.WriteLine();
        }
    }

    //一个数如果恰好等于它的所有真因子（即除了自身 外的所有因数）之和，这个数就称为"完数"。请编程求出1000以内的所有完数。
    public void TestPrint4()
    {
        for (int i = 2; i < 1000; i++)
        {
            int num = 1;
            for (int j = 2; j <= i / 2; j++)
            {
                if (i % j == 0)
                {
                    num += j;
                }
            }

            if (num == i)
            {
                Console.Write($"{i} ");
            }
        }
    }

    //键盘录入一个正整数，请求：1.它是几位数？2.逆序打印出各位数字。
    public void TestPrint5()
    {
        int num = Convert.ToInt32(Console.ReadLine());
        int count = 0;
        while (num != 0)
        {
            count++;
            Console.Write($"{num % 10}");
            num = num / 10;
        }

        Console.WriteLine($"   有{count}位  ");
    }

    //打印菱形，根据输入的行数，显示菱形形状
    public void TestPrint6()
    {
        /*
         *
         ***
         *****
         ***
         *
         */
        int n = Convert.ToInt32(Console.ReadLine());
        for (int i = 0; i < (n + 1) / 2; i++)
        {
            for (int j = 0; j < (n - 1) / 2 - i; j++)
            {
                Console.Write(" ");
            }

            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }

            Console.WriteLine();
        }

        for (int i = (n - 3) / 2; i >= 0; i--)
        {
            for (int j = 0; j < (n - 1) / 2 - i; j++)
            {
                Console.Write(" ");
            }

            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }

            Console.WriteLine();
        }
    }
}